package com.classbook.violet.baigiang.adapter;

import java.util.List;

import com.classbook.violet.baigiang.subject.UnitNode;
import com.classbook.violet.baigiang7.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListUnitAdapter extends BaseAdapter{
	
	private Context context;
	private List<UnitNode> listUnit;
	private static LayoutInflater inflater=null;
	
	public ListUnitAdapter (Context context, List<UnitNode> listLession){
		this.context = context;
		this.listUnit = listLession;
		inflater = ((Activity) context).getLayoutInflater();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listUnit.size();
	}

	@Override
	public UnitNode getItem(int position) {
		// TODO Auto-generated method stub
		return listUnit.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	public void disableCheck() {
		for (int i = 0; i < listUnit.size(); i++){
			listUnit.get(i).ischeck = false;
		}
	}
	
	public class LessionHolder {
		LinearLayout ll_row_unit;
		TextView tv_lession_label;
		ImageView iv_check;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		//Log.i("GETVIEW UNIT " + position, "" + listUnit.get(position).ischeck);
		View vi = convertView;
		if (convertView == null){
			vi = inflater.inflate(R.layout.row_lession, null);
			
			LessionHolder holder = new LessionHolder();
			holder.tv_lession_label = (TextView) vi.findViewById(R.id.tv_lession_label);
			holder.ll_row_unit = (LinearLayout) vi.findViewById(R.id.ll_row_unit);
			holder.iv_check = (ImageView) vi.findViewById(R.id.iv_check);
			vi.setTag(holder);
		}
		
		LessionHolder holder = (LessionHolder) vi.getTag();
		
		if (getItem(position).ischeck){
			holder.iv_check.setVisibility(View.VISIBLE);
		}else{
			holder.iv_check.setVisibility(View.INVISIBLE);
		}
		
		holder.tv_lession_label.setText(listUnit.get(position).label);
		return vi;
	}

}
